
type FileType = {
    suffix: string,
    mime: string,
}

export const DownloadFileTypeEnum: Record<string, FileType> = {
    XLSX: {
        suffix: 'xlsx',
        mime: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
    },
}

export const downloadBlobContent = (data:Blob, name:string, type:FileType)=>{
    if(data instanceof ArrayBuffer){
        // 判断是不是二进制数据
    }
    // 创建 Blob 对象; 如果blob中包含mime类型,可以不指定type
    const blob = new Blob([data], { type: type.mime });
    // 创建下载链接
    const url = URL.createObjectURL(blob);
    // 创建 <a> 元素
    const a = document.createElement('a');
    a.href = url;
    a.rel = 'noopener'
    a.download = `${name}.${type.suffix}`;

    // 模拟点击链接触发下载
    a.click();


    // 释放临时 URL, 100秒后
    setTimeout(()=>{
        URL.revokeObjectURL(url);
    },100)
}
